package com.example.oauth2.base.controller;

import com.example.oauth2.base.domain.SsoUser;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {



    /**
     * 资源API
     *
     * @return
     */
    @GetMapping("/api/userinfo")
    public ResponseEntity<SsoUser> getUserInfo() {
        User user = (User) SecurityContextHolder.getContext()
                .getAuthentication().getPrincipal();
        String email = user.getUsername() + "@anumbrella.net";

        SsoUser userInfo = new SsoUser();
        userInfo.setUsername(user.getUsername());
        return ResponseEntity.ok(userInfo);
    }
    /**
     * 资源API
     *
     * @return
     */
    @GetMapping("/hello")
    public ResponseEntity<String> htllo() {

        return ResponseEntity.ok("hello");
    }
}
